﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Taoyl.CodeTraceDAL;
using Taoyl.CodeTraceModels;
using xbd.DataConvertLib;

namespace Taoyl.CodeTraceBLL
{
    public class CodeRecordManager
    {
        private CodeRecordService recordService=new CodeRecordService();

        public OperateResult AddCodeRecord(CodeRecord record)
        {
            try
            {
              var res=  recordService.AddCodeRecord(record);
                return res == 1 ? OperateResult.CreateSuccessResult():OperateResult.CreateFailResult("受影响行数不为1:"+res);
            }
            catch (Exception ex)
            {
                return OperateResult.CreateFailResult(ex.Message);
            }
        }

        public OperateResult<List<CodeRecord>> QueryCodeRecords(DateTime start, DateTime end, string code, string result,bool order)
        {
            try
            {
                var list = recordService.QueryCodeRecords(start, end, code, result);
                if (!order)
                {
                     list.Reverse();
                }
                return OperateResult.CreateSuccessResult(list);
            }
            catch (Exception ex)
            {
               return OperateResult.CreateFailResult<List<CodeRecord>>(ex.Message);
            }
        }
    }
}
